﻿using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

/// <summary>
/// Summary description for QLHoaDonNhap
/// </summary>
public class QLHoaDonNhap
{
    DBConnection db = new DBConnection();
	public QLHoaDonNhap()
	{
		//
		// TODO: Add constructor logic here
		//
	}
    public DataTable Load_HDNhap()
    {
        string sql = "select hdnhap.sohdn,mancc,ngaynhap,mahoa,slnhap,dgnhap from hdnhap,cthdnhap where cthdnhap.sohdn=hdnhap.sohdn";
        return db.Get_data(sql);
    }
    public string Insert_HDNhap(string mancc,string ngaynhap)
    {
        string sql = "insert into hdnhap(mancc,ngaynhap) values(@mancc,@ngaynhap)";
        SqlParameter p1 = new SqlParameter("@mancc",mancc);
        SqlParameter p2 = new SqlParameter("@ngaynhap",ngaynhap);
        if (db.Get_data(sql, p1, p2) != null)
        {
            string sql1 = "select max(sohdn) from hdnhap";
            object kq = db.LayDuLieu(sql1);
            return kq.ToString();
        }
        return "";
    }
    public void Insert_CTHDNhap(string mahd,string mahoa,int sl,float dg)
    {
        string sql = "insert into cthdnhap values(@mahd,@mahoa,@sl,@dg)";
        SqlParameter p1 = new SqlParameter("@mahd", mahd);
        SqlParameter p2 = new SqlParameter("@mahoa", mahoa);
        SqlParameter p3 = new SqlParameter("@sl", sl);
        SqlParameter p4 = new SqlParameter("@dg", dg);
        db.thuchienlenh(sql, p1, p2, p3, p4);
    }

    public DataTable Load_DropNCC()
    {
        string sql = "select mancc,tenncc from nhacungcap";
        return db.Get_data(sql);
    }
    public DataTable Load_DropHoa()
    {
        string sql = "select mahoa,tenhoa from hoa";
        return db.Get_data(sql);
    }
}
